<template>
  <div>
    <img class="img" src="../../assets/wzy/imgs/bw.jpg" alt @click="sendID(mbj)" />
    <ul>
      <li class="li1">
        <h3>限时免费</h3>
        <p>VIP章节免费读</p>
        <i class="el-icon-time"></i>
        <p>{{ `${day}天 ${hr}: ${min}: ${sec}` }}</p>
      </li>
      <li v-for="item in freeBookData" :key="item.id" class="li2">
        <img :src="imgURL+item.cover" alt @click="sendID(item._id)" />
        <h3 @click="sendID(item._id)">{{item.title}}</h3>
        <p>5追书币/千字</p>
        <el-button round size="mini" @click="sendID(item._id)">免费阅读</el-button>
      </li>
    </ul>
    <div class="footer">
      <img src="../../assets/wzy/imgs/ft.png" alt />
      <!-- <img class="er" src="../../assets/wzy/imgs/liantu.png" alt /> -->
    </div>
  </div>
</template>

<script>
import { freeBook } from "../../api/wzy/index";
export default {
  data() {
    return {
      freeBookData: [],
      mbj: "5ac00ccb41e0e3490e55c7e2",
      imgURL: "http://statics.zhuishushenqi.com",
      day: 0,
      hr: 0,
      min: 0,
      sec: 0
    };
  },
  created() {
    freeBook().then(res => {
      this.freeBookData = res.data.ranking.books.splice(0, 6);
    });
    this.countdown();
  },
  methods: {
    //发送ID到localStorage中
    sendID(id) {
      localStorage.setItem("_id", id);
      this.$router.push({ path: "/bookdetails" });
    },
    countdown: function() {
      const end = Date.parse(new Date("2019-10-1"));
      const now = Date.parse(new Date());
      const msec = end - now;
      let day = parseInt(msec / 1000 / 60 / 60 / 24);
      let hr = parseInt((msec / 1000 / 60 / 60) % 24);
      let min = parseInt((msec / 1000 / 60) % 60);
      let sec = parseInt((msec / 1000) % 60);
      this.day = day;
      this.hr = hr > 9 ? hr : "0" + hr;
      this.min = min > 9 ? min : "0" + min;
      this.sec = sec > 9 ? sec : "0" + sec;
      const that = this;
      setTimeout(function() {
        that.countdown();
      }, 1000);
    }
  }
};
</script>
<style scoped>
.img {
  width: 100%;
  cursor: pointer;
}
ul {
  display: flex;
  margin-top: 40px;
  margin-bottom: 20px;
}
ul li {
  text-align: center;
  flex: 1;
  border: 1px solid #ddd;
  padding: 20px 0 10px 0;
}
ul li:hover {
  position: relative;
  z-index: 3;
  box-shadow: 0 5px 16px #d9d4c7;
}
ul li img {
  width: 80px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35), 0 0 5px #f9f2e9 inset;
  cursor: pointer;
}
ul .li2 h3 {
  font-size: 16px;
  height: 25px;
  line-height: 25px;
  font-weight: 400;
  cursor: pointer;
}
ul .li2 p {
  font-size: 12px;
  line-height: 20px;
  height: 20;
  color: #999;
  margin: 2px 0 5px 0;
  text-decoration: line-through;
}
ul .li2 .el-button {
  color: #ff5e66;
  border: 1px solid #ff5e66;
}
ul .li1 h3 {
  font-size: 18px;
  line-height: 21px;
  overflow: hidden;
  height: 21px;
  color: #ed4259;
  margin: 10px;
}
ul .li1 p:nth-of-type(1) {
  font-family: PingFangSC-Regular, "-apple-system", Simsun;
  font-size: 12px;
  overflow: hidden;
  height: 16px;
  padding: 2px 0;
  color: #999;
  margin-bottom: 20px;
  cursor: auto;
}
ul .li1 p:nth-of-type(2) {
  overflow: hidden;
  height: 22px;
  margin-bottom: 10px;
  color: #ff5e66;
  font-size: 16px;
}
ul .li1 .el-icon-time {
  font-size: 60px;
  display: block;
  height: 60px;
  margin: 10px 0;
  color: #ff5e66;
}
/* .er {
  margin-left: 40px;
  width: 300px;
  margin-bottom: 40px;
} */
.footer {
  text-align: center;
}
</style>